package day02;

import java.io.FileNotFoundException;

/**
 * 重写和重载
 * <day02>
 *
 * @Author Do Forest
 * @Date 2019/2/24 0023 23:17
 * @see
 */
public class OverridingMethod {

    public static void main(String[] args) {
        HomeDog hd = new HomeDog("阿黄");
        hd.desc();
    }


    public void sayHello(String str,int i) throws  NullPointerException{
        System.out.println("空指针异常");
    }

    public void sayHello(int i , String str){

    }

}

//基类
class Dog
{
    protected String name;

    public Dog(String name){
        this.name = name;
    }

    public void sayHello(String str,int i) throws  NullPointerException{
        System.out.println("空指针异常");
    }

    protected void desc(){
        System.out.println("I'm a dog");
    }
}


    //子类
    class HomeDog extends Dog
    {
        public HomeDog(String name){
            super(name);
        }
        // 当父类调用子类方法的时候，try catch块的时候，捕获的是父类的异常，但是子类如果抛出比父类更高的异常，则无法处理
//        public void sayHello(String str,int i) throws Exception{
//            System.out.println("空指针异常");
//        }


        //重写父类的方法
        public void desc(){
            System.out.println("这是一只狗，它的名字是"+this.name);
        }
    }
